package com.gzq.leet;

import java.math.BigInteger;

public class No9IsPalindromeInteger {

    public boolean s1(int x){
        int tar = x;
        boolean r=false;
        if(tar<0){
            return false;
        }
        else if(tar<10){
            return true;
        }
        //tar >= 10
        int maxDivisor=1_000_000_000;
        int tar_d=-1;
        for(int d=10;d<=maxDivisor;d*=10){
            if(tar/d < 10){//除非tar越界int最大值，否则tar_d一定会找到
                tar_d=d;
                break;
            }
        }

        while(tar_d>0){
            int left = tar/tar_d;
            int right= tar%10;
            if(left==right){
                r=true;
            }else{
                r=false;
                break;
            }
            tar = (tar%tar_d)/10;
            tar_d=tar_d/100;
        }

        return r;
    }

    //用反转数判断
    public boolean s2(int x){
        int tar=x;
        if(tar<0 || tar%10==0 && tar!=0){
            return false;
        }
        int revert=0;
        while(revert<tar){
            revert = revert*10 + tar%10;
            tar/=10;
        }
        return revert==tar || revert/10 == tar;
    }
}
